
#pragma once

ref class EventTest
{
public:
	EventTest(){ m_i = 0; };
	~EventTest(){};

	delegate void BeforeValueChange(int i);
	delegate void AfterValueChange(int i);

	event BeforeValueChange^ beforeValueChange;
	event AfterValueChange^ afterValueChange;

	void SetI(int i)
	{
		beforeValueChange(m_i);
		m_i = i;
		afterValueChange(m_i);
	}

private:
	int m_i;
};


void ValueChangeHanlder(int i)
{
	System::Console::WriteLine(i);
}

void Test1()
{
	EventTest^ e = gcnew EventTest();
	e->beforeValueChange += gcnew EventTest::BeforeValueChange(ValueChangeHanlder);
	e->afterValueChange += gcnew EventTest::AfterValueChange(ValueChangeHanlder);	
	e->SetI(10);
	e->SetI(20);
	e->SetI(30);
}